function messageHandle(msg, sender, callback) {
    let result = "";
    try {
        // First, validate the message's structure.
        if (msg.type == 'toggle-cmdwin') {
            toggleCmdWin();
        } else if (msg.type == "messageCallback") {
            api_message_callback(msg);
        } else if (msg.type == 'remote-command-run') {
            let item = msg.item;
            if (!window.shadowRoot) {
                toggleCmdWin();
            }

            toggleCmdWin(item.showType == 'background' ? 'hide' : 'show');
            if (item.cmds.length > 0) {
                let data = [];
                item.cmds.forEach(cmd => {
                    window.TerminalWinInstance.autofill = window.TerminalWinInstance.input.val();
                    window.TerminalWinInstance.handleInput(cmd, true, function (res) {
                        if (res) data.push(res);
                    });
                });
                result = data;
            }
        } else if (msg.type == 'remote-tab-run') {
            let item = msg.item;
            if (!window.shadowRoot) {
                toggleCmdWin();
            }

            toggleCmdWin(item.showType == 'background' ? 'hide' : 'show');
            window.TerminalWinInstance.tab_nums = 1;
            result = window.TerminalWinInstance.tabComplete(item.input, true);
        }
    } catch (error) {
        result = "Error : " + error
        console.log(result);
    }

    typeof callback == 'function' && callback(result);
}
